# -*- coding:utf-8 -*-


import jieba
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from wordcloud import WordCloud

''' 结巴分词'''


def cut_word():
    result = ''
    with open('comments.txt',  encoding='utf-8') as file:
        for line_word in file.readlines():
            cut_words = jieba.cut(line_word, cut_all=True)
            result += ' '.join(cut_words) + ' '
    print(result)
    return result


def word_cloud():
    # w_mask = np.array(Image.open('luke.jpg'))
    wc = WordCloud(font_path='SIMYOU.TTF', max_words=100, background_color='black'
                   ,width=900, height=450)
    wc.generate(cut_word())
    wc.to_file(r"temp.png")
    plt.imshow(wc)
    plt.axis("off")
    plt.show()


if __name__ == '__main__':
    word_cloud()




